const globalIp = getApp().globalData.userIp
Page({
  /**
   * 页面的初始数据
   */
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    arrayLineStatus: ['样品', '成品'],
    indexLineStatus: 0,
    status: '',
    DocStatusName: '',
    OrderNum: '',
    dateTime: '',
    CusOdNum: '',
    DocStatus: '',
    detail: []
  },

  select(options) {
    var that = this;
    wx.request({
      url: globalIp + 'home/ordr/xcxOrderVer3', 
      data: {
        openId: wx.getStorageSync('userInfo').openid || '',
        docEntry: options.item,
        value: '2'
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        if (res.data.success) {
          let data = res.data.jsonObject.data[0];
          let details = res.data.jsonObject.details;
          that.setData({
            status: data.DocStatus,
            DocStatusName: data.DocStatusName,
            OrderNum: data.OrderNum,
            dateTime: data.DocDueDate,
            CusOdNum: data.U_CusOdNum,
            DocStatus: data.Remark,
            detail: details
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },

  updateSO(e) {
    let that = this;
    wx.showModal({
      title: '申请删除',
      editable: true,
      placeholderText: '请输入申请删除原因',
      success: function (sm) {
        if (sm.confirm) {
          let item = e.currentTarget.dataset.item
          if (sm.content == "") {
            wx.showToast({
              title: "申请删除原因不能为空~",
              icon: "none",
            });
            return false;
          }
          wx.request({
            url: globalIp + 'home/ordr/xcxOrderVer2', 
            data: {
              docEntry: item.DocEntry,
              lineNum: item.LineNum,
              realName: sm.content,
              value: "3",
              pageSize: 0,
              openId: wx.getStorageSync('userInfo').openid || '',
            },
            header: {
              'content-type': 'application/json'
            },
            method: 'POST',
            success: function(res) {
              let op = {}
              op.item = item.DocEntry
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              })
              setTimeout(() => {
                that.onLoad(op);
              }, 2000)
            }
          })
        } 
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.select(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow(options) {
    
  }

})